package jinyilw.swing.rlaf.ui;

import jinyilw.swing.rlaf.theme.RThemeColor;

import javax.swing.JComponent;
import javax.swing.JSeparator;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicSeparatorUI;
import java.awt.Dimension;
import java.awt.Graphics;

/**
 * @author Jinyi
 */
public class RSeparatorUI extends BasicSeparatorUI
{
	public static ComponentUI createUI(JComponent c)
	{
		return new RSeparatorUI();
	}

	@Override
	public void update(Graphics g, JComponent c)
	{
		paint(g, c);
	}

	@Override
	public void paint(Graphics g, JComponent c)
	{
		getColor(c);
		Dimension s = c.getSize();
		if (((JSeparator) c).getOrientation() == JSeparator.VERTICAL)
		{
			g.setColor(shadow);
			g.drawLine(0, 0, 0, s.height);

			g.setColor(highlight);
			g.drawLine(1, 0, 1, s.height);
		} else
		{
			g.setColor(shadow);
			g.drawLine(0, 0, s.width, 0);

			g.setColor(highlight);
			g.drawLine(0, 1, s.width, 1);
		}
	}

	protected void getColor(JComponent c)
	{
		highlight = c.getForeground();
		if (highlight instanceof UIResource)
			highlight = RThemeColor.colorSet.borderColor;
//		shadow = c.getBackground();
//		if (shadow instanceof UIResource)
		shadow = RThemeColor.transThemeColor;
	}
}
